package com.edu.exam.entity.grading;

import com.edu.exam.enums.quality.monitoring.PriorityLevel;
import com.edu.exam.enums.grading.AnnotationType;
import com.edu.exam.enums.grading.GeometryType;
import com.edu.exam.enums.grading.FontStyle;
import com.edu.exam.enums.grading.BorderStyle;
import com.edu.exam.enums.grading.InteractionType;
import com.edu.exam.enums.grading.AnnotationLayer;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

/**
 * 批注实体类
 * 所属模块：B-06 成绩管理模块
 *
 * 根据E-04-05 网上批阅子模块设计实现
 * 对应annotation数据表
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class Annotation {

    @Id
    @Column(name = "annotation_id", length = 64)
    private String annotationId;

    /**
     * 图像ID
     */
    @Column(name = "image_id", nullable = false, length = 64)
    private String imageId;

    /**
     * 教师ID
     */
    @Column(name = "teacher_id", nullable = false, length = 64)
    private String teacherId;

    /**
     * 批注类型：TEXT（文本批注）、DRAWING（绘制批注）、MARKUP（标记批注）、AUDIO（音频批注）、CORRECTION（订正批注）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "annotation_type", nullable = false, length = 32)
    private AnnotationType annotationType;

    /**
     * 几何类型：RECTANGLE（矩形）、CIRCLE（圆形）、LINE（线条）、POLYGON（多边形）、FREEHAND（自由绘制）、ARROW（箭头）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "geometry_type", nullable = false, length = 32)
    private GeometryType geometryType;

    /**
     * 几何数据（JSON格式）
     */
    @Column(name = "geometry_data", nullable = false, length = 2000, columnDefinition = "TEXT")
    private String geometryData;

    /**
     * 样式配置（JSON格式）
     */
    @Column(name = "style_config", length = 1000, columnDefinition = "TEXT")
    private String styleConfig;

    /**
     * 批注内容
     */
    @Column(name = "content", length = 2000, columnDefinition = "TEXT")
    private String content;

    /**
     * 评论
     */
    @Column(name = "comment", length = 1000, columnDefinition = "TEXT")
    private String comment;

    /**
     * X坐标
     */
    @Column(name = "position_x", nullable = false, precision = 10, scale = 2)
    private Double positionX;

    /**
     * Y坐标
     */
    @Column(name = "position_y", nullable = false, precision = 10, scale = 2)
    private Double positionY;

    /**
     * 宽度
     */
    @Column(name = "width", precision = 10, scale = 2)
    private Double width;

    /**
     * 高度
     */
    @Column(name = "height", precision = 10, scale = 2)
    private Double height;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "deleted_time")
    private LocalDateTime deletedTime;

    /**
     * 删除人ID
     */
    @Column(name = "deleted_by", length = 64)
    private String deletedBy;

    /**
     * 删除原因
     */
    @Column(name = "deletion_reason", length = 500)
    private String deletionReason;

    /**
     * 批注颜色
     */
    @Column(name = "color", length = 16)
    private String color;

    /**
     * 线条宽度
     */
    @Column(name = "stroke_width", precision = 5, scale = 2)
    private Double strokeWidth;

    /**
     * 填充颜色
     */
    @Column(name = "fill_color", length = 16)
    private String fillColor;

    /**
     * 透明度（0-1）
     */
    @Column(name = "opacity", precision = 3, scale = 2)
    private Double opacity;

    /**
     * 字体大小
     */
    @Column(name = "font_size")
    private Integer fontSize;

    /**
     * 字体类型
     */
    @Column(name = "font_family", length = 64)
    private String fontFamily;

    /**
     * 字体颜色
     */
    @Column(name = "font_color", length = 16)
    private String fontColor;

    /**
     * 字体样式：NORMAL（正常）、BOLD（粗体）、ITALIC（斜体）、UNDERLINE（下划线）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "font_style", length = 16)
    private FontStyle fontStyle;

    /**
     * 边框样式：SOLID（实线）、DASHED（虚线）、DOTTED（点线）、DOUBLE（双线）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "border_style", length = 16)
    private BorderStyle borderStyle;

    /**
     * 阴影配置（JSON格式）
     */
    @Column(name = "shadow_config", length = 500)
    private String shadowConfig;

    /**
     * 动画效果（JSON格式）
     */
    @Column(name = "animation_effect", length = 500)
    private String animationEffect;

    /**
     * 交互类型：STATIC（静态）、CLICKABLE（可点击）、HOVERABLE（可悬停）、EDITABLE（可编辑）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "interaction_type", length = 16)
    private InteractionType interactionType;

    /**
     * 交互数据（JSON格式）
     */
    @Column(name = "interaction_data", length = 1000, columnDefinition = "TEXT")
    private String interactionData;

    /**
     * 优先级：LOW（低）、NORMAL（普通）、HIGH（高）
     * 映射到PriorityLevel枚举
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "priority", length = 16)
    private PriorityLevel priority;

    /**
     * 分类标签
     */
    @Column(name = "category", length = 64)
    private String category;

    /**
     * 标签（JSON格式）
     */
    @Column(name = "tags", length = 500)
    private String tags;

    /**
     * 关联的批注ID（用于回复或关联）
     */
    @Column(name = "related_annotation_id", length = 64)
    private String relatedAnnotationId;

    /**
     * 批注层级：BASE（基础）、OVERLAY（覆盖）、BACKGROUND（背景）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "layer", length = 16)
    private AnnotationLayer layer;

    /**
     * Z轴层级
     */
    @Column(name = "z_index")
    private Integer zIndex;

    /**
     * 是否锁定
     */
    @Column(name = "is_locked")
    private Boolean isLocked;

    /**
     * 锁定原因
     */
    @Column(name = "lock_reason", length = 200)
    private String lockReason;

    /**
     * 锁定时间
     */
    @Column(name = "lock_time")
    private LocalDateTime lockTime;

    /**
     * 锁定人ID
     */
    @Column(name = "locked_by", length = 64)
    private String lockedBy;

    /**
     * 是否隐藏
     */
    @Column(name = "is_hidden")
    private Boolean isHidden;

    /**
     * 隐藏原因
     */
    @Column(name = "hidden_reason", length = 200)
    private String hiddenReason;

    /**
     * 修改历史（JSON格式）
     */
    @Column(name = "modification_history", length = 2000, columnDefinition = "TEXT")
    private String modificationHistory;

    /**
     * 版本号
     */
    @Column(name = "annotation_version")
    private Integer annotationVersion;

    /**
     * 最后修改时间
     */
    @Column(name = "last_modified_time")
    private LocalDateTime lastModifiedTime;

    /**
     * 最后修改人ID
     */
    @Column(name = "last_modified_by", length = 64)
    private String lastModifiedBy;

    /**
     * 批注模板ID
     */
    @Column(name = "template_id", length = 64)
    private String templateId;

    /**
     * 是否为模板批注
     */
    @Column(name = "is_template")
    private Boolean isTemplate;

    /**
     * 模板名称
     */
    @Column(name = "template_name", length = 128)
    private String templateName;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "additional_attributes", length = 2000, columnDefinition = "TEXT")
    private String additionalAttributes;

    /**
     * 创建时间
     */
    @Column(name = "created_time", nullable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号（用于乐观锁）
     */
    @Version
    @Column(name = "version", nullable = false)
    private Integer version;

    // ================================
    // JPA 关联关系
    // ================================

    /**
     * 关联的批阅图像
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "image_id", insertable = false, updatable = false)
    private GradingImage gradingImage;

    // ================================
    // 枚举迁移完成
    // ================================
    // 以下枚举已成功迁移到grading包：
    // - AnnotationType: 批注类型
    // - GeometryType: 几何类型
    // - FontStyle: 字体样式
    // - BorderStyle: 边框样式
    // - InteractionType: 交互类型
    // - AnnotationLayer: 批注层级
}